package com.spring.aclservice.controller;

import com.spring.aclservice.entity.Permission;
import com.spring.aclservice.service.PermissionService;
import com.springsecurity.utils.utils.R;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 权限 菜单管理
 *
 * @author
 * @since
 */
@RestController
@RequestMapping("/admin/acl/permission")
// @CrossOrigin
public class PermissionController {

  @Autowired private PermissionService permissionService;

  // 获取全部菜单
  @ApiOperation(value = "查询所有菜单")
  @GetMapping
  public R indexAllPermission() {
    List<Permission> list = permissionService.queryAllMenu();
    return R.ok().data("children", list);
  }

  @ApiOperation(value = "给角色分配权限")
  @PostMapping("/doAssign")
  public R doAssign(String roleId, String[] permissionId) {
    permissionService.saveRolePermissionRealtionShipGuli(roleId, permissionId);
    return R.ok();
  }

  @ApiOperation(value = "根据角色获取菜单")
  @GetMapping("toAssign/{roleId}")
  public R toAssign(@PathVariable String roleId) {
    List<Permission> list = permissionService.selectAllMenu(roleId);
    return R.ok().data("children", list);
  }
}
